﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CrystalDecisions.CrystalReports.Engine;

namespace POS_NEW
{
    public partial class frmBaoCao_TheKho : Form
    {
        public frmBaoCao_TheKho()
        {
            InitializeComponent();
        }
        private void LoadcboHangHoa()
        {

           var colHangHoa = new[] { "ID Hàng hóa", "Hàng hóa", "Đơn vị" };
           DataTable     tbHangHoa = AccessDataLayer.ExecuteDT("spHangHoa_TraHang_Select", CommandType.StoredProcedure, "@Ten_HangHoa", "", "@AmKho", myProgress.AmKho)
                    .DefaultView.ToTable(true, colHangHoa);
            
            DataRow dr = tbHangHoa.NewRow();
            dr["ID Hàng hóa"] = -1;
            dr["Hàng hóa"] = " ----Chọn mặt hàng----";
            tbHangHoa.Rows.InsertAt(dr, 0);
            cboHangHoa.DataSource = null;
            cboHangHoa.ValueMember = "ID Hàng hóa";
            cboHangHoa.DisplayMember = "Hàng hóa";
            cboHangHoa.DataSource = tbHangHoa;
            cboHangHoa.DisplayLayout.Bands[0].Columns[0].Hidden = true;
            if (cboHangHoa.Rows.Count > 0)
                cboHangHoa.Value = -1;

        }
        private void btnThoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void frmBaoCaoXNT_TheoHangHoa_Load(object sender, EventArgs e)
        {
            LoadcboHangHoa();
        }

        private void btnEnter_Click(object sender, EventArgs e)
        {
                        DataTable dt = AccessDataLayer.ExecuteDT("spBaocao_TheKho", CommandType.StoredProcedure
                            , "@TuNgay", dtTuNgay.Value, "@ID_ChiNhanh", myProgress.ID_ChiNhanh,"@ID_HangHoa",cboHangHoa.Value);
                        POS_NEW.report.rptBaoCao_TheKho rpt = new report.rptBaoCao_TheKho();
                        //ReportDocument rpt = new ReportDocument();
                        //rpt.Load(Application.ExecutablePath.Substring(0, Application.ExecutablePath.LastIndexOf("bin")) + @"\report\rptBaoCao_TheKho.rpt");
                        //rpt.DataDefinition.FormulaFields["TuNgay"].Text = "'" + dtTuNgay.Value + "'";
                        //rpt.DataDefinition.FormulaFields["DenNgay"].Text = "'" + dtDenNgay.Value + "'";
                        rpt.SetDataSource(dt);
                        myProgress.SubReportHeader(rpt);
                        using (frmDisplayReport frm = new frmDisplayReport(rpt))
                        {
                            if (frm.ShowDialog() == DialogResult.Cancel)
                                rpt.Dispose();
                        }
        }

        private void dtTuNgay_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            if (dtTuNgay.Value != null)
            {
                cboHangHoa.Focus();
            }
        }

        private void cboHangHoa_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            if (cboHangHoa.Value.ToString() != "-1" && cboHangHoa.IsItemInList(cboHangHoa.Text))
                btnEnter.Focus();
        }

        private void frmBaoCaoXNT_TheoHangHoa_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Escape)
                this.Close();
        }
    }
}
